<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8">
    
    <title>Using F2PY &mdash; NumPy v1.18 Manual</title>
    
    <link rel="stylesheet" type="text/css" href="../_static/css/spc-bootstrap.css">
    <link rel="stylesheet" type="text/css" href="../_static/css/spc-extend.css">
    <link rel="stylesheet" href="../_static/scipy.css" type="text/css" >
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" >
    <link rel="stylesheet" href="../_static/graphviz.css" type="text/css" >
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '1.18.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script type="text/javascript" src="../_static/js/copybutton.js"></script>
    <link rel="author" title="About these documents" href="../about.html" >
    <link rel="index" title="Index" href="../genindex.html" >
    <link rel="search" title="Search" href="../search.html" >
    <link rel="top" title="NumPy v1.18 Manual" href="../index.html" >
    <link rel="up" title="F2PY Users Guide and Reference Manual" href="index.html" >
    <link rel="next" title="Using via numpy.distutils" href="distutils.html" >
    <link rel="prev" title="Using F2PY bindings in Python" href="python-usage.html" > 
  </head>
  <body>
<div class="container">
  <div class="top-scipy-org-logo-header" style="background-color: #a2bae8;">
    <a href="../index.html">
      <img border=0 alt="NumPy" src="../_static/numpy_logo.png"></a>
    </div>
  </div>
</div>


    <div class="container">
      <div class="main">
        
	<div class="row-fluid">
	  <div class="span12">
	    <div class="spc-navbar">
              
    <ul class="nav nav-pills pull-left">
        <li class="active"><a href="https://numpy.org/">NumPy.org</a></li>
        <li class="active"><a href="https://numpy.org/doc">Docs</a></li>
        
        <li class="active"><a href="../index.html">NumPy v1.18 Manual</a></li>
        

          <li class="active"><a href="index.html" accesskey="U">F2PY Users Guide and Reference Manual</a></li> 
    </ul>
              
              
    <ul class="nav nav-pills pull-right">
      <li class="active">
        <a href="../genindex.html" title="General Index"
           accesskey="I">index</a>
      </li>
      <li class="active">
        <a href="distutils.html" title="Using via numpy.distutils"
           accesskey="N">next</a>
      </li>
      <li class="active">
        <a href="python-usage.html" title="Using F2PY bindings in Python"
           accesskey="P">previous</a>
      </li>
    </ul>
              
	    </div>
	  </div>
	</div>
        

	<div class="row-fluid">
      <div class="spc-rightsidebar span3">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Using F2PY</a><ul>
<li><a class="reference internal" href="#command-f2py">Command <code class="docutils literal notranslate"><span class="pre">f2py</span></code></a></li>
<li><a class="reference internal" href="#python-module-numpy-f2py">Python module <code class="docutils literal notranslate"><span class="pre">numpy.f2py</span></code></a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="python-usage.html"
                        title="previous chapter">Using F2PY bindings in Python</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="distutils.html"
                        title="next chapter">Using via <code class="xref py py-obj docutils literal notranslate"><span class="pre">numpy.distutils</span></code></a></p>
<div id="searchbox" style="display: none" role="search">
  <h4>Quick search</h4>
    <div>
    <form class="search" action="../search.html" method="get">
      <input type="text" style="width: inherit;" name="q" />
      <input type="submit" value="search" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
          <div class="span9">
            
        <div class="bodywrapper">
          <div class="body" id="spc-section-body">
            
  <div class="section" id="using-f2py">
<h1>Using F2PY<a class="headerlink" href="#using-f2py" title="Permalink to this headline">¶</a></h1>
<p>F2PY can be used either as a command line tool <code class="docutils literal notranslate"><span class="pre">f2py</span></code> or as a Python
module <code class="docutils literal notranslate"><span class="pre">numpy.f2py</span></code>. While we try to install the command line tool as part
of the numpy setup, some platforms like Windows make it difficult to
reliably put the executable on the <code class="docutils literal notranslate"><span class="pre">PATH</span></code>. We will refer to <code class="docutils literal notranslate"><span class="pre">f2py</span></code>
in this document but you may have to run it as a module</p>
<p><code class="docutils literal notranslate"><span class="pre">`</span>
<span class="pre">python</span> <span class="pre">-m</span> <span class="pre">numpy.f2py</span>
<span class="pre">`</span></code></p>
<p>If you run <code class="docutils literal notranslate"><span class="pre">f2py</span></code> with no arguments, and the line <code class="docutils literal notranslate"><span class="pre">numpy</span> <span class="pre">Version</span></code> at the
end matches the NumPy version printed from <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">numpy.f2py</span></code>, then you
can use the shorter version. If not, or if you cannot run <code class="docutils literal notranslate"><span class="pre">f2py</span></code>, you should
replace all calls to <code class="docutils literal notranslate"><span class="pre">f2py</span></code> here with the longer version.</p>
<div class="section" id="command-f2py">
<h2>Command <code class="docutils literal notranslate"><span class="pre">f2py</span></code><a class="headerlink" href="#command-f2py" title="Permalink to this headline">¶</a></h2>
<p>When used as a command line tool, <code class="docutils literal notranslate"><span class="pre">f2py</span></code> has three major modes,
distinguished by the usage of <code class="docutils literal notranslate"><span class="pre">-c</span></code> and <code class="docutils literal notranslate"><span class="pre">-h</span></code> switches:</p>
<ol class="arabic">
<li><p>To scan Fortran sources and generate a signature file, use</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">f2py</span> <span class="o">-</span><span class="n">h</span> <span class="o">&lt;</span><span class="n">filename</span><span class="o">.</span><span class="n">pyf</span><span class="o">&gt;</span> <span class="o">&lt;</span><span class="n">options</span><span class="o">&gt;</span> <span class="o">&lt;</span><span class="n">fortran</span> <span class="n">files</span><span class="o">&gt;</span>   \
  <span class="p">[[</span> <span class="n">only</span><span class="p">:</span> <span class="o">&lt;</span><span class="n">fortran</span> <span class="n">functions</span><span class="o">&gt;</span>  <span class="p">:</span> <span class="p">]</span>                \
   <span class="p">[</span> <span class="n">skip</span><span class="p">:</span> <span class="o">&lt;</span><span class="n">fortran</span> <span class="n">functions</span><span class="o">&gt;</span>  <span class="p">:</span> <span class="p">]]</span><span class="o">...</span>            \
  <span class="p">[</span><span class="o">&lt;</span><span class="n">fortran</span> <span class="n">files</span><span class="o">&gt;</span> <span class="o">...</span><span class="p">]</span>
</pre></div>
</div>
<p>Note that a Fortran source file can contain many routines, and not
necessarily all routines are needed to be used from Python. So, you
can either specify which routines should be wrapped (in <code class="docutils literal notranslate"><span class="pre">only:</span> <span class="pre">..</span> <span class="pre">:</span></code>
part) or which routines F2PY should ignored (in <code class="docutils literal notranslate"><span class="pre">skip:</span> <span class="pre">..</span> <span class="pre">:</span></code> part).</p>
<p>If <code class="docutils literal notranslate"><span class="pre">&lt;filename.pyf&gt;</span></code> is specified as <code class="docutils literal notranslate"><span class="pre">stdout</span></code> then signatures
are send to standard output instead of a file.</p>
<p>Among other options (see below), the following options can be used
in this mode:</p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">--overwrite-signature</span></code></dt><dd><p>Overwrite existing signature file.</p>
</dd>
</dl>
</li>
<li><p>To construct an extension module, use</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">f2py</span> <span class="o">&lt;</span><span class="n">options</span><span class="o">&gt;</span> <span class="o">&lt;</span><span class="n">fortran</span> <span class="n">files</span><span class="o">&gt;</span>          \
  <span class="p">[[</span> <span class="n">only</span><span class="p">:</span> <span class="o">&lt;</span><span class="n">fortran</span> <span class="n">functions</span><span class="o">&gt;</span>  <span class="p">:</span> <span class="p">]</span>     \
   <span class="p">[</span> <span class="n">skip</span><span class="p">:</span> <span class="o">&lt;</span><span class="n">fortran</span> <span class="n">functions</span><span class="o">&gt;</span>  <span class="p">:</span> <span class="p">]]</span><span class="o">...</span> \
  <span class="p">[</span><span class="o">&lt;</span><span class="n">fortran</span> <span class="n">files</span><span class="o">&gt;</span> <span class="o">...</span><span class="p">]</span>
</pre></div>
</div>
<p>The constructed extension module is saved as
<code class="docutils literal notranslate"><span class="pre">&lt;modulename&gt;module.c</span></code> to the current directory.</p>
<p>Here <code class="docutils literal notranslate"><span class="pre">&lt;fortran</span> <span class="pre">files&gt;</span></code> may also contain signature files.
Among other options (see below), the following options can be used
in this mode:</p>
<dl>
<dt><code class="docutils literal notranslate"><span class="pre">--debug-capi</span></code></dt><dd><p>Add debugging hooks to the extension module. When using this
extension module, various information about the wrapper is printed
to standard output, for example, the values of variables, the
steps taken, etc.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">-include'&lt;includefile&gt;'</span></code></dt><dd><p>Add a CPP <code class="docutils literal notranslate"><span class="pre">#include</span></code> statement to the extension module source.
<code class="docutils literal notranslate"><span class="pre">&lt;includefile&gt;</span></code> should be given in one of the following forms:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="s2">&quot;filename.ext&quot;</span>
<span class="o">&lt;</span><span class="n">filename</span><span class="o">.</span><span class="n">ext</span><span class="o">&gt;</span>
</pre></div>
</div>
<p>The include statement is inserted just before the wrapper
functions. This feature enables using arbitrary C functions
(defined in <code class="docutils literal notranslate"><span class="pre">&lt;includefile&gt;</span></code>) in F2PY generated wrappers.</p>
<p>This option is deprecated. Use <code class="docutils literal notranslate"><span class="pre">usercode</span></code> statement to specify
C code snippets directly in signature files</p>
</dd>
</dl>
<p><code class="docutils literal notranslate"><span class="pre">--[no-]wrap-functions</span></code></p>
<blockquote>
<div><p>Create Fortran subroutine wrappers to Fortran functions.
<code class="docutils literal notranslate"><span class="pre">--wrap-functions</span></code> is default because it ensures maximum
portability and compiler independence.</p>
</div></blockquote>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">--include-paths</span> <span class="pre">&lt;path1&gt;:&lt;path2&gt;:..</span></code></dt><dd><p>Search include files from given directories.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">--help-link</span> <span class="pre">[&lt;list</span> <span class="pre">of</span> <span class="pre">resources</span> <span class="pre">names&gt;]</span></code></dt><dd><p>List system resources found by <code class="docutils literal notranslate"><span class="pre">numpy_distutils/system_info.py</span></code>.
For example, try <code class="docutils literal notranslate"><span class="pre">f2py</span> <span class="pre">--help-link</span> <span class="pre">lapack_opt</span></code>.</p>
</dd>
</dl>
</li>
<li><p>To build an extension module, use</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">f2py</span> <span class="o">-</span><span class="n">c</span> <span class="o">&lt;</span><span class="n">options</span><span class="o">&gt;</span> <span class="o">&lt;</span><span class="n">fortran</span> <span class="n">files</span><span class="o">&gt;</span>       \
  <span class="p">[[</span> <span class="n">only</span><span class="p">:</span> <span class="o">&lt;</span><span class="n">fortran</span> <span class="n">functions</span><span class="o">&gt;</span>  <span class="p">:</span> <span class="p">]</span>     \
   <span class="p">[</span> <span class="n">skip</span><span class="p">:</span> <span class="o">&lt;</span><span class="n">fortran</span> <span class="n">functions</span><span class="o">&gt;</span>  <span class="p">:</span> <span class="p">]]</span><span class="o">...</span> \
  <span class="p">[</span> <span class="o">&lt;</span><span class="n">fortran</span><span class="o">/</span><span class="n">c</span> <span class="n">source</span> <span class="n">files</span><span class="o">&gt;</span> <span class="p">]</span> <span class="p">[</span> <span class="o">&lt;.</span><span class="n">o</span><span class="p">,</span> <span class="o">.</span><span class="n">a</span><span class="p">,</span> <span class="o">.</span><span class="n">so</span> <span class="n">files</span><span class="o">&gt;</span> <span class="p">]</span>
</pre></div>
</div>
<p>If <code class="docutils literal notranslate"><span class="pre">&lt;fortran</span> <span class="pre">files&gt;</span></code> contains a signature file, then a source for
an extension module is constructed, all Fortran and C sources are
compiled, and finally all object and library files are linked to the
extension module <code class="docutils literal notranslate"><span class="pre">&lt;modulename&gt;.so</span></code> which is saved into the current
directory.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">&lt;fortran</span> <span class="pre">files&gt;</span></code> does not contain a signature file, then an
extension module is constructed by scanning all Fortran source codes
for routine signatures.</p>
<p>Among other options (see below) and options described in previous
mode, the following options can be used in this mode:</p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">--help-fcompiler</span></code></dt><dd><p>List available Fortran compilers.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">--help-compiler</span></code> [depreciated]</dt><dd><p>List available Fortran compilers.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">--fcompiler=&lt;Vendor&gt;</span></code></dt><dd><p>Specify Fortran compiler type by vendor.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">--f77exec=&lt;path&gt;</span></code></dt><dd><p>Specify the path to F77 compiler</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">--fcompiler-exec=&lt;path&gt;</span></code> [depreciated]</dt><dd><p>Specify the path to F77 compiler</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">--f90exec=&lt;path&gt;</span></code></dt><dd><p>Specify the path to F90 compiler</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">--f90compiler-exec=&lt;path&gt;</span></code> [depreciated]</dt><dd><p>Specify the path to F90 compiler</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">--f77flags=&lt;string&gt;</span></code></dt><dd><p>Specify F77 compiler flags</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">--f90flags=&lt;string&gt;</span></code></dt><dd><p>Specify F90 compiler flags</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">--opt=&lt;string&gt;</span></code></dt><dd><p>Specify optimization flags</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">--arch=&lt;string&gt;</span></code></dt><dd><p>Specify architecture specific optimization flags</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">--noopt</span></code></dt><dd><p>Compile without optimization</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">--noarch</span></code></dt><dd><p>Compile without arch-dependent optimization</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">--debug</span></code></dt><dd><p>Compile with debugging information</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">-l&lt;libname&gt;</span></code></dt><dd><p>Use the library <code class="docutils literal notranslate"><span class="pre">&lt;libname&gt;</span></code> when linking.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">-D&lt;macro&gt;[=&lt;defn=1&gt;]</span></code></dt><dd><p>Define macro <code class="docutils literal notranslate"><span class="pre">&lt;macro&gt;</span></code> as <code class="docutils literal notranslate"><span class="pre">&lt;defn&gt;</span></code>.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">-U&lt;macro&gt;</span></code></dt><dd><p>Define macro <code class="docutils literal notranslate"><span class="pre">&lt;macro&gt;</span></code></p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">-I&lt;dir&gt;</span></code></dt><dd><p>Append directory <code class="docutils literal notranslate"><span class="pre">&lt;dir&gt;</span></code> to the list of directories searched for
include files.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">-L&lt;dir&gt;</span></code></dt><dd><p>Add directory <code class="docutils literal notranslate"><span class="pre">&lt;dir&gt;</span></code> to the list of directories to  be  searched
for <code class="docutils literal notranslate"><span class="pre">-l</span></code>.</p>
</dd>
</dl>
<p><code class="docutils literal notranslate"><span class="pre">link-&lt;resource&gt;</span></code></p>
<blockquote>
<div><p>Link extension module with &lt;resource&gt; as defined by
<code class="docutils literal notranslate"><span class="pre">numpy_distutils/system_info.py</span></code>. E.g. to link with optimized
LAPACK libraries (vecLib on MacOSX, ATLAS elsewhere), use
<code class="docutils literal notranslate"><span class="pre">--link-lapack_opt</span></code>. See also <code class="docutils literal notranslate"><span class="pre">--help-link</span></code> switch.</p>
</div></blockquote>
<p>When building an extension module, a combination of the following
macros may be required for non-gcc Fortran compilers:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">-</span><span class="n">DPREPEND_FORTRAN</span>
<span class="o">-</span><span class="n">DNO_APPEND_FORTRAN</span>
<span class="o">-</span><span class="n">DUPPERCASE_FORTRAN</span>
</pre></div>
</div>
<p>To test the performance of F2PY generated interfaces, use
<code class="docutils literal notranslate"><span class="pre">-DF2PY_REPORT_ATEXIT</span></code>. Then a report of various timings is
printed out at the exit of Python. This feature may not work on
all platforms, currently only Linux platform is supported.</p>
<p>To see whether F2PY generated interface performs copies of array
arguments, use <code class="docutils literal notranslate"><span class="pre">-DF2PY_REPORT_ON_ARRAY_COPY=&lt;int&gt;</span></code>. When the size
of an array argument is larger than <code class="docutils literal notranslate"><span class="pre">&lt;int&gt;</span></code>, a message about
the coping is sent to <code class="docutils literal notranslate"><span class="pre">stderr</span></code>.</p>
</li>
</ol>
<p>Other options:</p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">-m</span> <span class="pre">&lt;modulename&gt;</span></code></dt><dd><p>Name of an extension module. Default is <code class="docutils literal notranslate"><span class="pre">untitled</span></code>. Don’t use this option
if a signature file (*.pyf) is used.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">--[no-]lower</span></code></dt><dd><p>Do [not] lower the cases in <code class="docutils literal notranslate"><span class="pre">&lt;fortran</span> <span class="pre">files&gt;</span></code>.  By default,
<code class="docutils literal notranslate"><span class="pre">--lower</span></code> is assumed with <code class="docutils literal notranslate"><span class="pre">-h</span></code> switch, and <code class="docutils literal notranslate"><span class="pre">--no-lower</span></code>
without the <code class="docutils literal notranslate"><span class="pre">-h</span></code> switch.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">--build-dir</span> <span class="pre">&lt;dirname&gt;</span></code></dt><dd><p>All F2PY generated files are created in <code class="docutils literal notranslate"><span class="pre">&lt;dirname&gt;</span></code>.  Default is
<code class="docutils literal notranslate"><span class="pre">tempfile.mkdtemp()</span></code>.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">--quiet</span></code></dt><dd><p>Run quietly.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">--verbose</span></code></dt><dd><p>Run with extra verbosity.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">-v</span></code></dt><dd><p>Print f2py version ID and exit.</p>
</dd>
</dl>
<p>Execute <code class="docutils literal notranslate"><span class="pre">f2py</span></code> without any options to get an up-to-date list of
available options.</p>
</div>
<div class="section" id="python-module-numpy-f2py">
<h2>Python module <code class="docutils literal notranslate"><span class="pre">numpy.f2py</span></code><a class="headerlink" href="#python-module-numpy-f2py" title="Permalink to this headline">¶</a></h2>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>The current Python interface to the <code class="docutils literal notranslate"><span class="pre">f2py</span></code> module is not mature and
may change in the future.</p>
</div>
<span class="target" id="module-numpy.f2py"></span><p>Fortran to Python Interface Generator.</p>
<dl class="function">
<dt id="numpy.f2py.run_main">
<code class="sig-prename descclassname">numpy.f2py.</code><code class="sig-name descname">run_main</code><span class="sig-paren">(</span><em class="sig-param">comline_list</em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/numpy/numpy/blob/v1.18.1/numpy/f2py/f2py2e.py#L408-L472"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#numpy.f2py.run_main" title="Permalink to this definition">¶</a></dt>
<dd><p>Equivalent to running:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">f2py</span> <span class="o">&lt;</span><span class="n">args</span><span class="o">&gt;</span>
</pre></div>
</div>
<p>where <code class="docutils literal notranslate"><span class="pre">&lt;args&gt;=string.join(&lt;list&gt;,'</span> <span class="pre">')</span></code>, but in Python.  Unless
<code class="docutils literal notranslate"><span class="pre">-h</span></code> is used, this function returns a dictionary containing
information on generated modules and their dependencies on source
files.  For example, the command <code class="docutils literal notranslate"><span class="pre">f2py</span> <span class="pre">-m</span> <span class="pre">scalar</span> <span class="pre">scalar.f</span></code> can be
executed from Python as follows</p>
<p>You cannot build extension modules with this function, that is,
using <code class="docutils literal notranslate"><span class="pre">-c</span></code> is not allowed. Use <code class="docutils literal notranslate"><span class="pre">compile</span></code> command instead</p>
<p class="rubric">Examples</p>
<pre class="literal-block">&gt;&gt;&gt; import numpy.f2py
&gt;&gt;&gt; r = numpy.f2py.run_main(['-m','scalar','doc/source/f2py/scalar.f'])
Reading fortran codes...
        Reading file 'doc/source/f2py/scalar.f' (format:fix,strict)
Post-processing...
        Block: scalar
                        Block: FOO
Building modules...
        Building module &quot;scalar&quot;...
        Wrote C/API module &quot;scalar&quot; to file &quot;./scalarmodule.c&quot;
&gt;&gt;&gt; print(r)
{'scalar': {'h': ['/home/users/pearu/src_cvs/f2py/src/fortranobject.h'],
         'csrc': ['./scalarmodule.c', 
                  '/home/users/pearu/src_cvs/f2py/src/fortranobject.c']}}
</pre>
</dd></dl>

<dl class="function">
<dt id="numpy.f2py.compile">
<code class="sig-prename descclassname">numpy.f2py.</code><code class="sig-name descname">compile</code><span class="sig-paren">(</span><em class="sig-param">source</em>, <em class="sig-param">modulename='untitled'</em>, <em class="sig-param">extra_args=''</em>, <em class="sig-param">verbose=True</em>, <em class="sig-param">source_fn=None</em>, <em class="sig-param">extension='.f'</em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/numpy/numpy/blob/v1.18.1/numpy/f2py/__init__.py#L23-L118"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#numpy.f2py.compile" title="Permalink to this definition">¶</a></dt>
<dd><p>Build extension module from a Fortran 77 source string with f2py.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl>
<dt><strong>source</strong><span class="classifier">str or bytes</span></dt><dd><p>Fortran source of module / subroutine to compile</p>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 1.16.0: </span>Accept str as well as bytes</p>
</div>
</dd>
<dt><strong>modulename</strong><span class="classifier">str, optional</span></dt><dd><p>The name of the compiled python module</p>
</dd>
<dt><strong>extra_args</strong><span class="classifier">str or list, optional</span></dt><dd><p>Additional parameters passed to f2py</p>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 1.16.0: </span>A list of args may also be provided.</p>
</div>
</dd>
<dt><strong>verbose</strong><span class="classifier">bool, optional</span></dt><dd><p>Print f2py output to screen</p>
</dd>
<dt><strong>source_fn</strong><span class="classifier">str, optional</span></dt><dd><p>Name of the file where the fortran source is written.
The default is to use a temporary file with the extension
provided by the <em class="xref py py-obj">extension</em> parameter</p>
</dd>
<dt><strong>extension</strong><span class="classifier">{‘.f’, ‘.f90’}, optional</span></dt><dd><p>Filename extension if <em class="xref py py-obj">source_fn</em> is not provided.
The extension tells which fortran standard is used.
The default is <em class="xref py py-obj">f</em>, which implies F77 standard.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in version 1.11.0.</span></p>
</div>
</dd>
</dl>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><dl class="simple">
<dt><strong>result</strong><span class="classifier">int</span></dt><dd><p>0 on success</p>
</dd>
</dl>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy.f2py</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">fsource</span> <span class="o">=</span> <span class="s1">&#39;&#39;&#39;</span>
<span class="gp">... </span><span class="s1">      subroutine foo</span>
<span class="gp">... </span><span class="s1">      print*, &quot;Hello world!&quot;</span>
<span class="gp">... </span><span class="s1">      end </span>
<span class="gp">... </span><span class="s1">&#39;&#39;&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">numpy</span><span class="o">.</span><span class="n">f2py</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="n">fsource</span><span class="p">,</span> <span class="n">modulename</span><span class="o">=</span><span class="s1">&#39;hello&#39;</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">hello</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">hello</span><span class="o">.</span><span class="n">foo</span><span class="p">()</span>
<span class="go"> Hello world!</span>
</pre></div>
</div>
</dd></dl>

</div>
</div>


          </div>
        </div>
          </div>
        </div>
      </div>
    </div>

    <div class="container container-navbar-bottom">
      <div class="spc-navbar">
        
      </div>
    </div>
    <div class="container">
    <div class="footer">
    <div class="row-fluid">
    <ul class="inline pull-left">
      <li>
        &copy; Copyright 2008-2019, The SciPy community.
      </li>
      <li>
      Last updated on Feb 20, 2020.
      </li>
      <li>
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.4.2.
      </li>
    </ul>
    </div>
    </div>
    </div>
  </body>
</html>